﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Client
{
    public static class formController
    {
        public static User state;
        private static List<Window> forms;
        
        static formController()
        { 
            forms = new List<Window>();

            forms.Add(new mainWindow());
            forms.Add(new newUser());
            forms.Add(new saunaMain());
            forms.Add(new AccountInfo());

            state = new User();
        }

        public static void ShowForm(System.Type formName)
        {
            
            //Loop through the forms and check for an instance
            foreach (Window form in forms)
            {
                if (form.GetType() == formName)
                {
                    form.Show();
                }
                else
                {
                    form.Hide();
                }
            }
        }

        private static Window GetFormInstance(System.Type formName)
        {
            //Loop through the forms and check for an instance
            foreach (Window form in forms)
            {
                if (form.GetType() == formName)
                {
                    return form;
                }
            }

            return null;
        }

        public static void userName(string name)
        {
            state.username = name;
        }

        public static void userPass(string pass)
        {
            state.password = pass;
        }

        public static void userEmail(string email)
        {
            state.email = email;
        }

        public static void userPhone(string phone)
        {
            state.phone = phone;
        }

        public static void userFirstName(string first)
        {
            state.firstname = first;
        }

        public static void userLastName(string last)
        {
            state.lastname = last;
        }

        public static void printState()
        {
            Console.WriteLine(state.username);
            Console.WriteLine(state.password);
            Console.WriteLine(state.email);
            Console.WriteLine(state.phone);
        }

        public static void editAccount(User userToEdit)
        {
            formController.ShowForm(typeof(AccountInfo));
            AccountInfo accountInfoForm = (AccountInfo)GetFormInstance(typeof(AccountInfo));
            accountInfoForm.tbxName.Text = userToEdit.username;

        }
    }
}
